package com.ifast.common.controller;


import java.util.Arrays;

import com.ifast.common.domain.TrademarkcatalogDO;
import com.ifast.common.service.TrademarkcatalogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ifast.common.base.AdminBaseController;
import com.ifast.common.utils.Result;

/**
 * 
 * <pre>
 * 商标分类
 *  @author  chenwenchao
 *  @date 2018-09-19 16:13:13
 * </pre>
 * <small> 2018-09-19 16:13:13 | chenwenchao</small>
 */
@Controller
@RequestMapping("/common/trademarkcatalog")
public class TrademarkcatalogController extends AdminBaseController {
	@Autowired
	private TrademarkcatalogService trademarkcatalogService;
	
	@GetMapping()
	@RequiresPermissions("common:trademarkcatalog:trademarkcatalog")
	String Trademarkcatalog(){
	    return "common/trademarkcatalog/trademarkcatalog";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("common:trademarkcatalog:trademarkcatalog")
	public Result<Page<TrademarkcatalogDO>> list(TrademarkcatalogDO trademarkcatalogDTO){
        Wrapper<TrademarkcatalogDO> wrapper = new EntityWrapper<TrademarkcatalogDO>().orderBy("id", false);
        Page<TrademarkcatalogDO> page = trademarkcatalogService.selectPage(getPage(TrademarkcatalogDO.class), wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("common:trademarkcatalog:add")
	String add(){
	    return "common/trademarkcatalog/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("common:trademarkcatalog:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		TrademarkcatalogDO trademarkcatalog = trademarkcatalogService.selectById(id);
		model.addAttribute("trademarkcatalog", trademarkcatalog);
	    return "common/trademarkcatalog/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("common:trademarkcatalog:add")
	public Result<String> save( TrademarkcatalogDO trademarkcatalog){
		trademarkcatalogService.insert(trademarkcatalog);
        return Result.ok();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("common:trademarkcatalog:edit")
	public Result<String>  update( TrademarkcatalogDO trademarkcatalog){
		boolean update = trademarkcatalogService.updateById(trademarkcatalog);
		return update ? Result.ok() : Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("common:trademarkcatalog:remove")
	public Result<String>  remove( Integer id){
		trademarkcatalogService.deleteById(id);
        return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("common:trademarkcatalog:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] ids){
		trademarkcatalogService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
